﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Converters="clr-namespace:MahApps.Metro.Converters">

    <Converters:ToUpperConverter x:Key="ToUpperConverter" />

    <Style x:Key="MetroGridViewScrollViewerStyle"
           TargetType="{x:Type ScrollViewer}"
           BasedOn="{StaticResource {x:Static GridView.GridViewScrollViewerStyleKey}}">
        <Setter Property="Focusable"
                Value="false" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid Background="{TemplateBinding Background}"
                          SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <DockPanel Margin="{TemplateBinding Padding}">
                            <ScrollViewer DockPanel.Dock="Top"
                                          Focusable="false"
                                          HorizontalScrollBarVisibility="Hidden"
                                          VerticalScrollBarVisibility="Hidden">
                                <GridViewHeaderRowPresenter AllowsColumnReorder="{Binding TemplatedParent.View.AllowsColumnReorder, RelativeSource={RelativeSource TemplatedParent}}"
                                                            ColumnHeaderContainerStyle="{Binding TemplatedParent.View.ColumnHeaderContainerStyle, RelativeSource={RelativeSource TemplatedParent}}"
                                                            ColumnHeaderToolTip="{Binding TemplatedParent.View.ColumnHeaderToolTip, RelativeSource={RelativeSource TemplatedParent}}"
                                                            ColumnHeaderStringFormat="{Binding TemplatedParent.View.ColumnHeaderStringFormat, RelativeSource={RelativeSource TemplatedParent}}"
                                                            ColumnHeaderContextMenu="{Binding TemplatedParent.View.ColumnHeaderContextMenu, RelativeSource={RelativeSource TemplatedParent}}"
                                                            ColumnHeaderTemplate="{Binding TemplatedParent.View.ColumnHeaderTemplate, RelativeSource={RelativeSource TemplatedParent}}"
                                                            Columns="{Binding TemplatedParent.View.Columns, RelativeSource={RelativeSource TemplatedParent}}"
                                                            ColumnHeaderTemplateSelector="{Binding TemplatedParent.View.ColumnHeaderTemplateSelector, RelativeSource={RelativeSource TemplatedParent}}"
                                                            Margin="2,0,2,0"
                                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </ScrollViewer>
                            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                                    CanContentScroll="{TemplateBinding CanContentScroll}"
                                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                                    Content="{TemplateBinding Content}"
                                                    KeyboardNavigation.DirectionalNavigation="Local"
                                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </DockPanel>
                        <ScrollBar x:Name="PART_HorizontalScrollBar"
                                   Cursor="Arrow"
                                   Maximum="{TemplateBinding ScrollableWidth}"
                                   Minimum="0.0"
                                   Orientation="Horizontal"
                                   Grid.Row="1"
                                   Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                                   Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                                   ViewportSize="{TemplateBinding ViewportWidth}" />
                        <ScrollBar x:Name="PART_VerticalScrollBar"
                                   Cursor="Arrow"
                                   Grid.Column="1"
                                   Maximum="{TemplateBinding ScrollableHeight}"
                                   Minimum="0.0"
                                   Orientation="Vertical"
                                   Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                   Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                                   ViewportSize="{TemplateBinding ViewportHeight}" />
                        <!-- this is from original style, but we don't want it!!!
                        <DockPanel Background="{Binding Background, ElementName=PART_VerticalScrollBar}"
                                   Grid.Column="1"
                                   LastChildFill="false"
                                   Grid.Row="1">
                            <Rectangle DockPanel.Dock="Left"
                                       Fill="White"
                                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                                       Width="1" />
                            <Rectangle DockPanel.Dock="Top"
                                       Fill="White"
                                       Height="1"
                                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" />
                        </DockPanel>
                        -->
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- 
    Do not set CanContentScroll=True below. This breaks the scrolling for groups with more items that will fit on screen. 
    It also (setting true) has the ugly side effect of scrolling the entire group and not the items. The downside is we lose 
    virtualisation http://serialseb.blogspot.com/2007/09/wpf-tips-7-smooth-scrolling.html 
    -->
    <Style x:Key="MetroListView"
           TargetType="{x:Type ListView}">
        <Setter Property="BorderBrush"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="Background"
                Value="{DynamicResource WhiteBrush}" />
        <Setter Property="BorderThickness"
                Value="0 1 0 0" />
        <Setter Property="ScrollViewer.CanContentScroll"
                Value="False" />
        <Setter Property="AlternationCount"
                Value="2" />

        <!-- Things taken from the original template. -->
        <Setter Property="SnapsToDevicePixels"
                Value="true" />
        <Setter Property="OverridesDefaultStyle"
                Value="true" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListView">
                    <Border x:Name="Border"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="true">
                        <ScrollViewer Padding="{TemplateBinding Padding}"
                                      Style="{DynamicResource MetroGridViewScrollViewerStyle}">
                            <ItemsPresenter />
                        </ScrollViewer>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsGrouping"
                                 Value="true">
                            <Setter Property="ScrollViewer.CanContentScroll"
                                    Value="false" />
                        </Trigger>
                        <Trigger Property="IsEnabled"
                                 Value="false">
                            <Setter TargetName="Border"
                                    Property="BorderBrush"
                                    Value="{DynamicResource GrayBrush9}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="VirtualisedMetroListView"
           TargetType="{x:Type ListView}"
           BasedOn="{StaticResource MetroListView}">
        <Setter Property="VirtualizingStackPanel.IsVirtualizing"
                Value="True" />
        <Setter Property="VirtualizingStackPanel.VirtualizationMode"
                Value="Recycling" />
        <Setter Property="ScrollViewer.IsDeferredScrollingEnabled"
                Value="True" />
        <Setter Property="ScrollViewer.CanContentScroll"
                Value="True" />
    </Style>

    <Style x:Key="MetroListViewItem"
           TargetType="{x:Type ListViewItem}">
        <Setter Property="Foreground"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="MinHeight"
                Value="25" />
        <Setter Property="Margin"
                Value="0,0,0,0" />
        <Setter Property="Border.BorderBrush"
                Value="{DynamicResource GrayBrush1}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListViewItem}">
                    <Border x:Name="Bd"
                            Background="{TemplateBinding Background}"
                            SnapsToDevicePixels="true">
                        <Grid>
                            <GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                <GridViewRowPresenter.Resources>
                                    <Style TargetType="{x:Type TextBlock}">
                                        <Setter Property="Foreground"
                                                Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}, Path=Foreground}" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}}"
                                                         Value="True">
                                                <Setter Property="Foreground"
                                                        Value="{DynamicResource AccentSelectedColorBrush}" />
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
                                                         Value="False">
                                                <Setter Property="Foreground"
                                                        Value="{DynamicResource GrayNormalBrush}" />
                                            </DataTrigger>
                                            <MultiDataTrigger>
                                                <MultiDataTrigger.Conditions>
                                                    <Condition Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
                                                               Value="False" />
                                                    <Condition Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}}"
                                                               Value="True" />
                                                </MultiDataTrigger.Conditions>
                                                <MultiDataTrigger.Setters>
                                                    <Setter Property="Foreground"
                                                            Value="{DynamicResource AccentSelectedColorBrush}" />
                                                </MultiDataTrigger.Setters>
                                            </MultiDataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </GridViewRowPresenter.Resources>
                            </GridViewRowPresenter>
                            <ContentPresenter x:Name="contentPresenter"
                                              Visibility="Collapsed" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="GridView.ColumnCollection"
                                 Value="{x:Null}">
                            <Setter TargetName="contentPresenter"
                                    Property="Visibility"
                                    Value="Visible" />
                        </Trigger>
                        <Trigger Property="IsSelected"
                                 Value="true">
                            <Setter TargetName="Bd"
                                    Property="BorderBrush"
                                    Value="#FF143c65" />
                            <Setter Property="Background"
                                    TargetName="Bd"
                                    Value="{DynamicResource AccentColorBrush}"></Setter>
                            <Setter Property="Foreground"
                                    Value="{DynamicResource AccentSelectedColorBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter TargetName="Bd"
                                    Property="Background"
                                    Value="{DynamicResource AccentColorBrush3}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected"
                                           Value="true" />
                                <Condition Property="Selector.IsSelectionActive"
                                           Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Background"
                                    TargetName="Bd"
                                    Value="{DynamicResource AccentColorBrush2}" />
                            <Setter Property="BorderBrush"
                                    TargetName="Bd"
                                    Value="#FF143c65" />
                            <Setter Property="Foreground"
                                    Value="{DynamicResource AccentSelectedColorBrush}" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsEnabled"
                                           Value="False" />
                                <Condition Property="IsSelected"
                                           Value="True" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="Bd"
                                        Property="Background"
                                        Value="{DynamicResource GrayBrush7}" />
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!--Gives the impression that items cannot be selected on the ListView-->
    <Style x:Key="NonSelectableListViewContainerStyle"
           TargetType="{x:Type ListViewItem}">
        <Setter Property="Foreground"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="MinHeight"
                Value="25" />
        <Setter Property="Margin"
                Value="0,0,0,0" />
        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="Border.BorderBrush"
                Value="{DynamicResource GrayBrush1}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListViewItem}">
                    <Border x:Name="Bd"
                            Background="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding Border.BorderThickness}"
                            SnapsToDevicePixels="true">
                        <GridViewRowPresenter VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver"
                                 Value="True">
                            <Setter TargetName="Bd"
                                    Property="Background"
                                    Value="#e0eff8" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="ItemsControl.AlternationIndex"
                     Value="0">
                <Setter Property="Background"
                        Value="{DynamicResource AlternateRow1BackgroundBrush}" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex"
                     Value="1">
                <Setter Property="Background"
                        Value="{DynamicResource AlternateRow2BackgroundBrush}" />
                <Setter Property="Border.BorderThickness"
                        Value="0 1 0 1" />
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="GridViewColumnHeaderGripper"
           TargetType="Thumb">
        <Setter Property="Width"
                Value="18" />
        <Setter Property="Background"
                Value="LightGray" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}"
                            Background="Transparent"
                            Margin="0 0 0 2">
                        <Rectangle HorizontalAlignment="Center"
                                   Width="1"
                                   Fill="{TemplateBinding Background}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="MetroGridViewColumnHeader"
           TargetType="GridViewColumnHeader">
        <Setter Property="Foreground"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="SnapsToDevicePixels"
                Value="True" />
        <Setter Property="HorizontalContentAlignment"
                Value="Left" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="Padding"
                Value="4 2 4 2" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="GridViewColumnHeader">
                    <Grid>
                        <Rectangle Fill="Transparent"
                                   IsHitTestVisible="True" />
                        <Border x:Name="HeaderBorder"
                                Padding="{TemplateBinding Padding}">
                            <ContentPresenter x:Name="HeaderContent"
                                              Content="{TemplateBinding Content}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              Margin="0,0,0,1"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              RecognizesAccessKey="True"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Border>
                        <Thumb x:Name="PART_HeaderGripper"
                               HorizontalAlignment="Right"
                               Margin="0,0,-9,0"
                               Style="{StaticResource GridViewColumnHeaderGripper}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsPressed"
                                 Value="true">
                            <Setter TargetName="HeaderBorder"
                                    Property="Background"
                                    Value="{DynamicResource GrayBrush8}" />
                            <Setter TargetName="HeaderContent"
                                    Property="Margin"
                                    Value="1,1,0,0" />
                        </Trigger>
                        <Trigger Property="IsEnabled"
                                 Value="false">
                            <Setter Property="Foreground"
                                    Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock TextBlock.FontWeight="SemiBold"
                               Text="{Binding Converter={StaticResource ToUpperConverter}}" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Role"
                     Value="Floating">
                <Setter Property="Opacity"
                        Value="0.7" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="GridViewColumnHeader">
                            <Canvas Name="PART_FloatingHeaderCanvas">
                                <Rectangle Fill="#60000000"
                                           Width="{TemplateBinding ActualWidth}"
                                           Height="{TemplateBinding ActualHeight}" />
                            </Canvas>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type GridViewColumnHeader}"
           BasedOn="{StaticResource MetroGridViewColumnHeader}" />
</ResourceDictionary>
